package com.queryBuilder.dao.impl;

import java.io.Serializable;
import java.util.List;

import javax.annotation.Resource;

import org.json.JSONArray;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.stereotype.Repository;

import com.queryBuilder.dao.QueryBuilderDao;
import com.queryBuilder.entity.QueryBuilder;
@Repository	//存储层注解
public  class QueryBuilderDaoImpl implements QueryBuilderDao{
	@Resource
	private HibernateTemplate hibernateTemplate;
	
	@SuppressWarnings("unchecked")
	public JSONArray findByClsAndPro(String clsName, String proName) {
//		List<Object> list = hibernateTemplate.find("select "+proName+" from "+clsName);
//		
		List<Object> list = hibernateTemplate.find("select "+proName+" from "+clsName);
		JSONArray jsonArray = new JSONArray();
		if(list.size()>0){
			for(Object object :list){
				System.out.println(object);
				jsonArray.put(object.toString());
			}
		}
		return jsonArray;
	}

	

	public <T> T findById(Class<T> type, Serializable id) {
		// TODO Auto-generated method stub
		return null;
	}

	public void save(Object... entities) {
		// TODO Auto-generated method stub
		
	}

	public void update(Object... entities) {
		// TODO Auto-generated method stub
		
	}

	public void saveOrUpdate(Object entity) {
		// TODO Auto-generated method stub
		
	}

	public void delete(Object... entities) {
		// TODO Auto-generated method stub
		
	}

	public void deleteById(Class<?> type, Serializable id) {
		// TODO Auto-generated method stub
		
	}

	public void refresh(Object... entities) {
		// TODO Auto-generated method stub
		
	}

	public void flush() {
		// TODO Auto-generated method stub
		
	}



	@SuppressWarnings("unchecked")
	public List<QueryBuilder> findAll(Class type) {
		System.out.println();
		List<QueryBuilder> list = (List<QueryBuilder>) hibernateTemplate.loadAll(type);  
        return list;
	}


}
